package com.study.d025paint;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

/**图片填充
*@description
*@author xtayhame
*date 2020年3月20日
*version
*since v1.0
*/
public class ImagePatternMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();
		GridPane gridPane = new GridPane();
		gridPane.setVgap(5);
		gridPane.setHgap(1);

		for(int i=0;i<5;i++){
			Rectangle rectangle = new Rectangle(100, 100);
			gridPane.add(rectangle, i, 1);
			rectangle.setFill(Color.GRAY);
		}

		Circle circle = new Circle(100);

		Polygon p = new Polygon(10);
		p.setLayoutX(10);
        p.setLayoutY(10);
        p.getPoints().add(50.0);
        p.getPoints().add(0.0);
        p.getPoints().add(200.0);
        p.getPoints().add(200.0);
        p.getPoints().add(40.0);
        p.getPoints().add(200.0);




		anchorPane.getChildren().addAll(gridPane,circle,p);
		AnchorPane.setLeftAnchor(circle, 20.0);
		AnchorPane.setTopAnchor(circle, 150.0);
		AnchorPane.setLeftAnchor(p, 400.0);
		AnchorPane.setTopAnchor(p, 150.0);


		stage.setScene(new Scene(anchorPane, 800, 500));
		stage.show();



		//填充图片
		Image image = new Image("icon/01.jpg");
		ImagePattern imagePattern = new ImagePattern(new Image("icon/01.jpg"));

		Rectangle  rectangle1 = (Rectangle)gridPane.getChildren().get(0);
		rectangle1.setFill(imagePattern);

		Rectangle  rectangle2 = (Rectangle)gridPane.getChildren().get(1);
		rectangle2.setFill(new ImagePattern(image, 0, 0, 20, 20, true));


		circle.setFill(imagePattern);



	}
}
